<?php foreach ($edit_data as $key): ?>
<form class="form-horizontal" id="locationForm">
	<div class="ibox float-e-margins">
		<div class="ibox-title" style="border: none;">
			<h5 style="color: #00afef"><i>Edit</i></h5>
				<div class="ibox-tools add">
					<button class="btn btn-primary btn-sm save-btn-tab">Save</button>
					<a id="cancel_edit" class="btn-outline btn btn-info btn-sm cancel-btn-tab" >Cancel</a>
				</div>
		</div>
		
		<input type="hidden" name="employeeID" value="<?php echo $key->employee_id; ?>">

		<div class="ibox-content">
				<div class="form-group">
            <label style="text-align: right;" class="col-lg-4 control-label">Prefix</label>
            <div class="col-lg-4">
                <input readonly name="empPrefix" type="text" value="<?php echo $key->prefix; ?>" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-4 control-label">First Name</label>
            <div class="col-lg-4">
                <input readonly name="empFName" type="text" value="<?php echo $key->first_name; ?>" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-4 control-label">Middle Initial</label>
            <div class="col-lg-4">
                <input readonly maxlength="1" value="<?php echo $key->middle_init; ?>" name="empMInit" type="text" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-4 control-label">Last Name</label>
            <div class="col-lg-4">
                <input readonly name="empLName" type="text" value="<?php echo $key->last_name; ?>" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-4 control-label">Sex</label>
            <div class="col-lg-4">
                <select disabled name="sex" class="form-control">
                    <option value="">--</option>
                    <?php foreach($sex as $s): ?>
                    <option value="<?php echo $s->lookup_code; ?>" <?php echo ($key->sex == $s->lookup_code ? 'selected' : '')  ?>><?php echo $s->meaning; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-4 control-label">Department</label>
            <div class="col-lg-4">
                <select name="empDep_e" class="form-control">
                    <option value="">--</option>
                    <?php foreach($emp_dep as $ed): ?>
                    <option value="<?php echo $ed->lookup_code; ?>" <?php echo ($key->department == $ed->lookup_code ? 'selected' : '')  ?>><?php echo $ed->meaning; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-4 control-label">Position</label>
            <div class="col-lg-4">
                <select name="empPos_e" class="form-control">
                    <option value="">--</option>
                    <?php foreach($emp_pos as $ep): ?>
                    <option value="<?php echo $ep->lookup_code; ?>" <?php echo ($key->position == $ep->lookup_code ? 'selected' : '')  ?>><?php echo $ep->meaning; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>
      </div>
			</form>
		</div>
	</div>
<?php endforeach;?>
	<script type="text/javascript">
	$(document).ready(function() {
		$('select').chosen({width: '100%'});
		$('select').trigger('chosen:updated');
		$('#locationForm').data('serialize',$('#locationForm').serialize());
		$('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green'
        });

        $("#locationForm").validate({
                 rules: {
                     locCode_e: {
                        required: true
                     },
                     locDesc_e: {
                     	required : true
                     }
                 },
                 submitHandler: function(form){
                    $.ajax({
	                    url:"<?php echo base_url($this->session->userdata('forajax') . '/update'); ?>",
	                    method:'post',
	                    data:$('#locationForm').serialize(),
	                    dataType:'json',
	                    success: function (data) {
	                         if(data.err == 1){
		                    	notifymsg('danger',data.msg);
		                    }else{
		                        $('#edit-link').remove();
		                        $('#edit').remove();
		                        $('#tab-list-2 a:first').tab('show');
		                        $('#count_edit').val('0');
		                        notifymsg('success','<b>Success</b>: Data Saved.');
		                    }
	                    },
	                    beforeSend: function(){

	                    }
	                });
                 }
        });
		function alert_cancel(){
		            if($('#locationForm').serialize()!=$('#locationForm').data('serialize')){
		                swal({
                              title: "Are you sure?",
                              text: "Your work will not be save",
                              type: "warning",
                              showCancelButton: true,
                              confirmButtonColor: "#DD6B55",
                              confirmButtonText: "Leave",
                              cancelButtonText: "Stay",
                              closeOnConfirm: true,
                              closeOnCancel: true },
                          function (isConfirm) {
                              if (isConfirm) {
                                  close_edit(); active_search();
                                  notifymsg("hide","hide");
                              } else {
                                  swal("Cancelled");
                              }
                          });
		                }else{
		                close_edit(); active_search();
		                notifymsg("hide","hide");
		            }
		        }
		        $('#cancel_edit').click(function(){
		            alert_cancel();
		        });
		      $('#editX').click(function(){
		            alert_cancel();
		      });
	});
	</script>